package com.luo.chengrui.module.sa.dal.mysql.role;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import com.luo.chengrui.module.sa.dal.dataobject.role.PermissionDO;
import com.luo.chengrui.module.sa.dal.dataobject.role.PermissionViewDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import com.luo.chengrui.module.sa.controller.admin.role.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 角色菜单权限 Mapper
 *
 * @author 诚睿
 */
@Mapper
public interface PermissionMapper extends BaseMapperX<PermissionDO> {

    default PageResult<PermissionDO> selectPage(PermissionPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PermissionDO>()
                .eqIfPresent(PermissionDO::getRoleId, reqVO.getRoleId())
                .eqIfPresent(PermissionDO::getMenuId, reqVO.getMenuId())
                .eqIfPresent(PermissionDO::getPermissionKind, reqVO.getPermissionKind())
                .eqIfPresent(PermissionDO::getVersion, reqVO.getVersion())
                .orderByDesc(PermissionDO::getId));
    }

    default List<PermissionDO> selectList(PermissionExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<PermissionDO>()
                .eqIfPresent(PermissionDO::getRoleId, reqVO.getRoleId())
                .eqIfPresent(PermissionDO::getMenuId, reqVO.getMenuId())
                .eqIfPresent(PermissionDO::getPermissionKind, reqVO.getPermissionKind())
                .eqIfPresent(PermissionDO::getVersion, reqVO.getVersion())
                .orderByDesc(PermissionDO::getId));
    }

    default List<PermissionDO> selectListByRoleId(String roleId) {
        return selectList(PermissionDO::getRoleId, roleId);
    }

    default List<PermissionDO> selectListByRoleId(Collection<String> roleIds) {
        return selectList(PermissionDO::getRoleId, roleIds);
    }

    default void deleteListByRoleIdAndMenuIds(String roleId, Collection<Long> menuIds) {
        delete(new LambdaQueryWrapper<PermissionDO>()
                .eq(PermissionDO::getRoleId, roleId)
                .in(PermissionDO::getMenuId, menuIds));
    }

    void clearDeletedData(String roleId);

    List<PermissionViewDO> getMenuListByRoleIds(@Param("roleIds") List<String> roleIds);
}
